// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1
import Qt.labs.particles 1.0

CharacterBase{
    width: 10
    height: 10
    color: "#000000dd"

    property int burst: 0
    property int moveDiv: 0 //0移動なし 1:左 2:右

    //左へ移動している時のキラキラ
    Particles {
        anchors.centerIn: parent.Center
        width: 1
        height: parent.height * 2
        source: "images/star.png"
        visible: (moveDiv === 1) ? true : false
        lifeSpan: 2000
        count: 30
        angle: 0
//        angleDeviation: 45
        velocity: 30
        velocityDeviation: 10
    }
    //右へ移動している時のキラキラ
    Particles {
        anchors.centerIn: parent.Center
        width: 1
        height: parent.height * 2
        source: "images/star.png"
        visible: (moveDiv === 2) ? true : false
        lifeSpan: 2000
        count: 30
        angle: 180
//        angleDeviation: 45
        velocity: 30
        velocityDeviation: 10
    }
    //キャラクタ
    Image{
        id: _image
        anchors.centerIn: parent
        fillMode: Image.PreserveAspectCrop
        source: "./images/homu1.png"

        Rectangle{
            id: _hitEffect
            anchors.fill: parent
            color: "#00ffffff"
            ColorAnimation{
                id: _hitAmin
                target: _hitEffect
                property: "color"
                from: "#66ffffff"
                to: "#00ffffff"
                duration: 100
            }
        }
    }

    onBurstChanged: {
        switch(burst){
        case 0:
            _image.source = "./images/homu1.png";
            break;
        case 1:
            _image.source = "./images/homu2.png";
            break;
        case 2:
            _image.source = "./images/homu3.png";
            break;
        default:
            _image.source = "./images/homu1.png";
            break;
        }
        burst = burst;
    }

    function move(isLeft, isRight){
        if(isLeft){
            // 左が押されてる
            x -= 5;
            moveDiv = 1;
        }else if(isRight){
            // 右が押されてる
            x += 5;
            moveDiv = 2;
        }else{
            moveDiv = 0;
        }

        if(x < 0){
            x = 0;
        }else if((x + width) > fieldWidth){
            x = fieldWidth - width;
        }
    }

    function getBullet(){
        return {"_qml": "PlayerBullet.qml"
            , "_charId": -1
            , "_x": x + width / 2
            , "_y": y
            , "_fieldWidth": fieldWidth
            , "_fieldHeight": fieldHeight
            , "_scorepoint": 100
            , "_hitpoint": 1
            , "_ratio": ratio
            , "_init":{}
        };
    }

    // 弾があたったときの処理
    onHited: {
        _hitAmin.start();
    }
}
